import axios from 'axios';

const apiClient = axios.create({
  baseURL: 'http://localhost:8080', 
  withCredentials: false,
  headers: {
    Accept: 'application/json',
    'Content-Type': 'application/json'
  }
});

export default {
  // 任务相关API
  getTasks(params = {}) {
    return apiClient.get('/api/tasks', { params });
  },
  getTask(id) {
    return apiClient.get(`/api/tasks/${id}`);
  },
  createTask(task) {
    return apiClient.post('/api/tasks', task);
  },
  updateTask(id, task) {
    return apiClient.put(`/api/tasks/${id}`, task);
  },
  deleteTask(id) {
    return apiClient.delete(`/api/tasks/${id}`);
  },
  updateTaskStatus(id, status) {
    return apiClient.patch(`/api/tasks/${id}/status`, { status });
  },
  
  // 分类相关API
  getCategories() {
    return apiClient.get('/api/categories');
  },
  createCategory(category) {
    return apiClient.post('/api/categories', category);
  },
  updateCategory(id, category) {
    return apiClient.put(`/api/categories/${id}`, category);
  },
  deleteCategory(id) {
    return apiClient.delete(`/api/categories/${id}`);
  },
  
  // 统计API
  getStats() {
    return apiClient.get('/api/stats');
  }
};